using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintItemPerTag
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintItemPerTag(clsProject cProject)
		{
			//Discarded unreachable code: IL_022b, IL_0242, IL_024d, IL_025d, IL_030f, IL_0311, IL_0325, IL_0347
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				clsCollection<string> clsCollection = cProject.ItemTags();
				num2 = 3;
				if (clsCollection.Count() == 0)
				{
					num2 = 4;
					clsShared.cLang.TransMsgBox("This report only works if you specify tags for one or more items.");
				}
				else
				{
					num2 = 6;
					frmPickTags frmPickTags = new frmPickTags(clsCollection);
					num2 = 7;
					frmPickTags.ShowDialog();
					num2 = 8;
					if (frmPickTags.colPickedTags.Count() != 0)
					{
						num2 = 10;
						clsCollection = frmPickTags.colPickedTags;
						num2 = 11;
						clsShared.cSubs.BusyMouse();
						num2 = 12;
						clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Items per Tag");
						num2 = 13;
						clsReport.AddTitle();
						num2 = 14;
						clsReport.AddCentered(cProject.Title + " by " + cProject.AuthorName);
						num2 = 15;
						clsReport.AddBR(2);
						num2 = 16;
						clsReport.SetTableBorder(1);
						num2 = 17;
						clsReport.OpenTable("cellpadding=5");
						num2 = 18;
						IEnumerator enumerator = clsCollection.GetEnumerator();
						while (enumerator.MoveNext())
						{
							string text = Conversions.ToString(enumerator.Current);
							num2 = 19;
							int num3 = 0;
							num2 = 20;
							clsReport.OpenRow();
							num2 = 21;
							clsReport.AddCell(clsReport.Bold(text), "align=left");
							num2 = 22;
							clsReport.CloseRow();
							num2 = 23;
							IEnumerator enumerator2 = cProject.Items.GetEnumerator();
							while (enumerator2.MoveNext())
							{
								clsItem clsItem = (clsItem)enumerator2.Current;
								num2 = 24;
								if (clsItem.PassesTagFilter(text))
								{
									num2 = 25;
									num3++;
									num2 = 26;
									clsReport.OpenRow();
									num2 = 27;
									clsReport.AddCell(clsItem.Title);
									num2 = 28;
									clsReport.CloseRow();
								}
								num2 = 29;
							}
							num2 = 30;
							if (enumerator2 is IDisposable)
							{
								(enumerator2 as IDisposable).Dispose();
							}
							num2 = 31;
						}
						num2 = 32;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						num2 = 33;
						clsReport.CloseTable();
						num2 = 34;
						clsReport.AddFooter(App.Title);
						num2 = 35;
						clsReport.Show();
						num2 = 36;
						PrintProgressEvent?.Invoke("Printing Complete");
						num2 = 37;
						clsShared.cSubs.NormalMouse();
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0345: Could not find block for branch target IL_0311*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
